home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / cyberxxxsrc / decoder / txt / decodergb.c < prev    next >
C/C++ Source or Header  |  1999-02-08  |  9KB  |  383 lines

  1. /*
  2. sc:c/sc opt txt/DecodeRGB.c
  3. */
  4.  
  5. #include "Decode.h"
  6. #include "YUV.h"
  7. #include "Utils.h"
  8. #include "GlobalVars.h"
  9.  
  10. struct RGBData {
  11.   ulong dummy;
  12. };
  13.  
  14. /* /// "DecodeRGB4toRGB()" */
  15. __asm void DecodeRGB4toRGB(REG(a0) uchar *from,
  16.                            REG(a1) uchar *to,
  17.                            REG(d0) ulong width,
  18.                            REG(d1) ulong height,
  19.                            REG(d2) ulong encSize,
  20.                            REG(a2) struct RGBData *spec)
  21. {
  22.   long x, y;
  23.   uchar *iptr;
  24.   ulong oddCnt, rowInc=width*4;
  25.  
  26.   oddCnt=((width & 0x03)==1)?1:0;
  27.  
  28.   iptr=to+(height-1)*width*4;
  29.   for (y=height-1; y>0; y--) {
  30.     RGBTriple *ip=(RGBTriple *)iptr;
  31.     for (x=width; x>0; x-=2) {
  32.       uchar d, d1;
  33.       d=*from++;
  34.       d1=(d>>4) & 0x0f;
  35.       Idx332ToRGB(d1,ip[0].red,ip[0].green,ip[0].blue);
  36.       d1=d & 0x0f;
  37.       Idx332ToRGB(d1,ip[1].red,ip[1].green,ip[1].blue);
  38.       ip+=2;
  39.     }
  40.     from+=oddCnt; /* for (x=oddCnt; x>0; x--) from++; */
  41.     iptr-=rowInc;
  42.   }
  43. }
  44. /* \\\ */
  45.  
  46. /* /// "DecodeRGB4to332()" */
  47. __asm void DecodeRGB4to332(REG(a0) uchar *from,
  48.                            REG(a1) uchar *to,
  49.                            REG(d0) ulong width,
  50.                            REG(d1) ulong height,
  51.                            REG(d2) ulong encSize,
  52.                            REG(a2) struct RGBData *spec)
  53. {
  54.   long x, y;
  55.   uchar *iptr;
  56.   ulong oddCnt, rowInc=width;
  57.  
  58.   oddCnt=((width & 0x03)==1)?1:0;
  59.  
  60.   iptr=to+(height-1)*width;
  61.   for (y=height-1; y>0; y--) {
  62.     ulong d;
  63.     uchar *ip=iptr;
  64.     for (x=width; x>0; x-=2) {
  65.       d=*from++;
  66.       ip[0]=remap[d>>4];
  67.       ip[1]=remap[d & 0x0f];
  68.       ip+=2;
  69.     }
  70.     from+=oddCnt; /* for (x=oddCnt; x>0; x--) from++; */
  71.     iptr-=rowInc;
  72.   }
  73. }
  74. /* \\\ */
  75.  
  76. /* /// "DecodeRGB8toRGB()" */
  77. __asm void DecodeRGB8toRGB(REG(a0) uchar *from,
  78.                            REG(a1) uchar *to,
  79.                            REG(d0) ulong width,
  80.                            REG(d1) ulong height,
  81.                            REG(d2) ulong encSize,
  82.                            REG(a2) struct RGBData *spec)
  83. {
  84.   long x, y;
  85.   uchar *iptr;
  86.   ulong oddCnt;
  87.   ulong rowInc=width*4;
  88.  
  89.   oddCnt=4-(width & 0x03);
  90.   if (oddCnt==4) oddCnt=0;
  91.  
  92.   iptr=to+(height-1)*width*4;
  93.   for (y=height-1; y>0; y--) {
  94.     uchar *ip=iptr;
  95.     for (x=width; x>0; x--) {
  96.       uchar d=*from++;
  97.       Idx332ToRGB(d,ip[1],ip[2],ip[3]);
  98.       ip+=4;
  99.     }
  100.     from+=oddCnt;
  101.     iptr-=rowInc;
  102.   }
  103. }
  104. /* \\\ */
  105.  
  106. /* /// "DecodeRGB8to332()" */
  107. __asm void DecodeRGB8to332(REG(a0) uchar *from,
  108.                            REG(a1) uchar *to,
  109.                            REG(d0) ulong width,
  110.                            REG(d1) ulong height,
  111.                            REG(d2) ulong encSize,
  112.                            REG(a2) struct RGBData *spec)
  113. {
  114.   long x, y;
  115.   uchar *iptr, *ip;
  116.   ulong oddCnt, rowInc=width;
  117.  
  118.   oddCnt=4-(width & 0x03);
  119.   if (oddCnt==4) oddCnt=0;
  120.  
  121.   iptr=to+(height-1)*width;
  122.   for (y=height-1; y>0; y--) {
  123.     ip=iptr;
  124.     for (x=width; x>0; x--) {
  125.       *ip++=remap[*from++];
  126.     }
  127.     from+=oddCnt;
  128.     iptr-=rowInc;
  129.   }
  130. }
  131. /* \\\ */
  132.  
  133. /* /// "DecodeRGB16toRGB()" */
  134. __asm void DecodeRGB16toRGB(REG(a0) uchar *from,
  135.                             REG(a1) uchar *to,
  136.                             REG(d0) ulong width,
  137.                             REG(d1) ulong height,
  138.                             REG(d2) ulong encSize,
  139.                             REG(a2) struct RGBData *spec)
  140. {
  141.   long x, y;
  142.   uchar *iptr;
  143.   ulong rowInc=width*4;
  144.  
  145.   iptr=to+(height-1)*width*4;
  146.   for (y=height-1; y>0; y--) {
  147.     uchar *ip=iptr;
  148.     for (x=width; x>0; x--) {
  149.       ulong col;
  150.       col=get16pc(from);
  151.       RGB16toRGB24(col,ip[1],ip[2],ip[3]);
  152.       ip+=4;
  153.     }
  154.     iptr-=rowInc;
  155.   }
  156. }
  157. /* \\\ */
  158.  
  159. /* /// "DecodeRGB16to332()" */
  160. __asm void DecodeRGB16to332(REG(a0) uchar *from,
  161.                             REG(a1) uchar *to,
  162.                             REG(d0) ulong width,
  163.                             REG(d1) ulong height,
  164.                             REG(d2) ulong encSize,
  165.                             REG(a2) struct RGBData *spec)
  166. {
  167.   long x, y;
  168.   uchar *iptr;
  169.   ulong rowInc=width;
  170.  
  171.   iptr=to+(height-1)*width;
  172.   for (y=height-1; y>0; y--) {
  173.     uchar *ip=iptr;
  174.     for (x=width; x>0; x--) {
  175.       ulong col;
  176.       col=get16pc(from);
  177.       RGB16toColor(col,*ip++);
  178.     }
  179.     iptr-=rowInc;
  180.   }
  181. }
  182. /* \\\ */
  183.  
  184. /* /// "DecodeRGB16to332Dith()" */
  185. __asm void DecodeRGB16to332Dith(REG(a0) uchar *from,
  186.                                 REG(a1) uchar *to,
  187.                                 REG(d0) ulong width,
  188.                                 REG(d1) ulong height,
  189.                                 REG(d2) ulong encSize,
  190.                                 REG(a2) struct RGBData *spec)
  191. {
  192.   long x, y;
  193.   uchar *iptr;
  194.   ulong rowInc=width;
  195.  
  196.   iptr=to+(height-1)*width;
  197.   for (y=height-1; y>0; y--) {
  198.     long re=0, ge=0, be=0;
  199.     uchar *ip=iptr;
  200.     for (x=width; x>0; x--) {
  201.       long r, g, b, col;
  202.       col=get16pc(from);
  203.       RGB16toRGB24(col,r,g,b);
  204.       DitherGetRGB(r,g,b,re,ge,be,*ip++);
  205.     }
  206.     iptr-=rowInc;
  207.   }
  208. }
  209. /* \\\ */
  210.  
  211. /* /// "DecodeRGB24toRGB()" */
  212. __asm void DecodeRGB24toRGB(REG(a0) uchar *from,
  213.                             REG(a1) uchar *to,
  214.                             REG(d0) ulong width,
  215.                             REG(d1) ulong height,
  216.                             REG(d2) ulong encSize,
  217.                             REG(a2) struct RGBData *spec)
  218. {
  219.   long x, y;
  220.   uchar *iptr;
  221.   uchar oddFlag;
  222.   ulong rowInc=width*4;
  223.  
  224.   iptr=to+(height-1)*width*4;
  225.   oddFlag=width & 0x01;
  226.   for (y=height-1; y>0; y--) {
  227.     uchar *ip=iptr;
  228.     for (x=width; x>0; x--) {
  229.       ip[1]=from[2];
  230.       ip[2]=from[1];
  231.       ip[3]=from[0];
  232.       ip+=4;
  233.       from+=3;
  234.     }
  235.     if (oddFlag) from++;
  236.     iptr-=rowInc;
  237.   }
  238. }
  239. /* \\\ */
  240.  
  241. /* /// "DecodeRGB24to332()" */
  242. __asm void DecodeRGB24to332(REG(a0) uchar *from,
  243.                             REG(a1) uchar *to,
  244.                             REG(d0) ulong width,
  245.                             REG(d1) ulong height,
  246.                             REG(d2) ulong encSize,
  247.                             REG(a2) struct RGBData *spec)
  248. {
  249.   long x, y;
  250.   uchar *iptr;
  251.   uchar oddFlag;
  252.   ulong rowInc=width;
  253.  
  254.   iptr=to+(height-1)*width;
  255.   oddFlag=width & 0x01;
  256.   for (y=height-1; y>0; y--) {
  257.     uchar *ip=iptr;
  258.     for (x=width; x>0; x--) {
  259.       RGB24toColor(from[2],from[1],from[0],*ip++);
  260.       from+=3;
  261.     }
  262.     if (oddFlag) from++;
  263.     iptr-=rowInc;
  264.   }
  265. }
  266. /* \\\ */
  267.  
  268. /* /// "DecodeRGB24to332Dith()" */
  269. __asm void DecodeRGB24to332Dith(REG(a0) uchar *from,
  270.                                 REG(a1) uchar *to,
  271.                                 REG(d0) ulong width,
  272.                                 REG(d1) ulong height,
  273.                                 REG(d2) ulong encSize,
  274.                                 REG(a2) struct RGBData *spec)
  275. {
  276.   long x, y;
  277.   uchar *iptr;
  278.   uchar oddFlag;
  279.   ulong rowInc=width;
  280.  
  281.   iptr=to+(height-1)*width;
  282.   oddFlag=width & 0x01;
  283.   for (y=height-1; y>0; y--) {
  284.     long re=0, ge=0, be=0;
  285.     uchar *ip=iptr;
  286.     for (x=width; x>0; x--) {
  287.       ulong r, g, b;
  288.       r=from[2];
  289.       g=from[1];
  290.       b=from[0];
  291.       DitherGetRGB(r,g,b,re,ge,be,*ip++);
  292.       from+=3;
  293.     }
  294.     if (oddFlag) from++;
  295.     iptr-=rowInc;
  296.   }
  297. }
  298. /* \\\ */
  299.  
  300. /* /// "DecodeRGB32toRGB()" */
  301. __asm void DecodeRGB32toRGB(REG(a0) uchar *from,
  302.                             REG(a1) uchar *to,
  303.                             REG(d0) ulong width,
  304.                             REG(d1) ulong height,
  305.                             REG(d2) ulong encSize,
  306.                             REG(a2) struct RGBData *spec)
  307. {
  308.   long x,y;
  309.   uchar *iptr;
  310.   ulong rowInc=width*4;
  311.  
  312.   iptr=to+(height-1)*width*4;
  313.   for (y=height-1; y>0; y--) {
  314.     uchar *ip=iptr;
  315.     for (x=width; x>0; x--) {
  316.       ip[1]=from[2];
  317.       ip[2]=from[1];
  318.       ip[3]=from[0];
  319.       ip+=4;
  320.       from+=4;
  321.     }
  322.     iptr-=rowInc;
  323.   }
  324. }
  325. /* \\\ */
  326.  
  327. /* /// "DecodeRGB32to332()" */
  328. __asm void DecodeRGB32to332(REG(a0) uchar *from,
  329.                             REG(a1) uchar *to,
  330.                             REG(d0) ulong width,
  331.                             REG(d1) ulong height,
  332.                             REG(d2) ulong encSize,
  333.                             REG(a2) struct RGBData *spec)
  334. {
  335.   long x,y;
  336.   uchar *iptr;
  337.   ulong rowInc=width;
  338.  
  339.   iptr=to+(height-1)*width;
  340.   for (y=height-1; y>0; y--) {
  341.     uchar *ip=iptr;
  342.     for (x=width; x>0; x--) {
  343.       RGB24toColor(from[2],from[1],from[0],*ip++);
  344.       from+=4;
  345.     }
  346.     iptr-=rowInc;
  347.   }
  348. }
  349. /* \\\ */
  350.  
  351. /* /// "DecodeRGB32to332Dith()" */
  352. __asm void DecodeRGB32to332Dith(REG(a0) uchar *from,
  353.                                 REG(a1) uchar *to,
  354.                                 REG(d0) ulong width,
  355.                                 REG(d1) ulong height,
  356.                                 REG(d2) ulong encSize,
  357.                                 REG(a2) struct RGBData *spec)
  358. {
  359.   long x, y;
  360.   uchar *iptr;
  361.   uchar oddFlag;
  362.   ulong rowInc=width;
  363.  
  364.   iptr=to+(height-1)*width;
  365.   oddFlag=width & 0x01;
  366.   for (y=height-1; y>0; y--) {
  367.     long re=0, ge=0, be=0;
  368.     uchar *ip=iptr;
  369.     for (x=width; x>0; x--) {
  370.       ulong r, g, b;
  371.       r=from[2];
  372.       g=from[1];
  373.       b=from[0];
  374.       DitherGetRGB(r,g,b,re,ge,be,*ip++);
  375.       from+=4;
  376.     }
  377.     if (oddFlag) from++;
  378.     iptr-=rowInc;
  379.   }
  380. }
  381. /* \\\ */
  382.  
  383.